<?php
include_once 'lib/zingme-sdk/BaseZingMe.php';
include_once 'lib/zingme-sdk/ZME_Me.php';
include_once 'lib/zingme-sdk/ZME_User.php';

$config_dev = array(
	'appname' => 'zigo',
	'apikey' => 'e5e7fd50431a48a7b3206e13cdfd8207',
	'secretkey' => 'e4ad44ef86ce4a2f8435438b05cf1471',
	'env' => 'development'
);

$config_live = array(
	'appname' => 'test1',
	'apikey' => '4bc575ea590a0b297e526815a38e9565',
	'secretkey' => '8295a3d9b21c624ac0ff353733d227b8',
	'env' => 'production'
);

$config = $config_dev;

$zm_Me = new ZME_Me($config);
$signed_request = $_GET['signed_request'];


//////////////////////////
$access_token = $zm_Me->getAccessTokenFromSignedRequest($signed_request);
$_SESSION['access_token'] = $access_token;
//echo "1. test get accesstoken = " . $access_token;
//echo "<br><br>";

//$profile = "singer.phamquynhanh";

//$isfan = $zm_Me->isFanOf($access_token, $profile);

//var_dump($isfan);

//exit();
//get userid from signed_request
$uid = $zm_Me->getUserLoggedIn($signed_request);
$_SESSION['userIdZing'] = $uid;
//echo "2.test get uid of user logged by singed request : ";
//var_dump($uid);

//echo "<br><br>";

//echo "3.test get me info from accesstoken : ";
$me = $zm_Me->getInfo($access_token,$fields="id,username,displayname,tinyurl");
$_SESSION['userNameZing'] = $me["username"];
$_SESSION['userDisplayZing'] = $me["displayname"];
$_SESSION['userAvatarZing'] = $me["tinyurl"];
//var_dump($me);

//echo "<br><br>";

//echo "4.test get me friends from accesstoken : ";
//$friends = $zm_Me->getFriends($access_token);
//echo "totalfriend = " . count($friends);
//echo "<br>list = ";//var_dump($friends);

//echo "<br><br>";

//echo "5.test get 20 friends' info from friend list above : ";
//$uids = array();

//for($i=0;$i<2;$i++) {
//	$uids[] = $friends[$i];
//}

//$zm_User = new ZME_User($config);

//$user = $zm_User->getInfo($access_token, $uids,$fields="id,username,displayname");

//var_dump($user);

//echo "<br><br>";

?>

